﻿using AutoMapper;
using MRSite.Common.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MRSite.AutoMapper.Attributes
{
    public class AutoMapBothAttribute : BaseMapAttribute
    {
        public AutoMapBothAttribute(params Type[] targetTypes) : base(targetTypes)
        {

        }

        public override void CreateMap(IMapperConfigurationExpression configurationExpression, Type type)
        {
            if (TargetTypes.IsNullOrEmpty())
            {
                return;
            }

            foreach (var item in TargetTypes)
            {
                configurationExpression.CreateMap(type, item, MemberList.Source);
                configurationExpression.CreateMap(item, type, MemberList.Destination);
            }
        }
    }
}
